#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
long long int A[200005], B[200005], M[200005];
int main()
{
	long long int n, m, L, R;
	while(cin >> n >> m)
	{
		long long int sum = 0;
		memset(A, 0, sizeof(A));
		memset(B, 0, sizeof(B));
		while(m--)
		{
			cin >> L >> R;
			A[L]++;
			B[R]++;
		}
		A[0] = 0;
		B[0] = 0;
		M[1] = A[1];
		for(int i = 2; i <= n; i++)
		{
			A[i] += A[i - 1];
			B[i] += B[i - 1];
			if(B[i] == B[i - 1]) M[i] = A[i] - B[i];
			else M[i] = A[i] - B[i] + (B[i] - B[i - 1]);
		}
		sort(M + 1, M + n + 1);
		for(int i = 1; i <= n; i++)
			sum += (i * M[i]);
		cout << sum << endl;
	}
	return 0;
}
